package com.tanhua.server.interceptor;

/*
* threadlocal的工具类
* */

import com.tanhua.model.db.User;

public class UserHolder {

    public static ThreadLocal<User> local=new ThreadLocal<>();

    //保存
    public static void saveUser(User user){
        local.set(user);
    }

    //获取
    public  static User getUser(){
       return local.get();
    }

    //从threadlocal中取出用户id
    public static Long getUserId() {
        return local.get().getId();
    }

    //从threadlocal中取出用户手机号
    public static String getMobile() {
        return local.get().getMobile();
    }

    //删除threalocal中的数据
    public static void remove() {
        local.remove();
    }

}
